package com.hiwhitley.easy.day28;

/**
 * Created by hiwhitley on 2016/11/4.
 */
public class ThirdMaximumNumber_414 {
    public int thirdMax(int[] nums) {
        Integer first = null;
        Integer second = null;
        Integer third = null;
        for (int n : nums) {
            if (first == null || n > first) {
                third = second;
                second = first;
                first = n;
            } else if (second == null || n > second) {
                if (n == first) continue;
                third = second;
                second = n;
            } else if (third == null || n > third) {
                if (n == second) continue;
                third = n;
            }
        }
        return third == null ? first : third;
    }


    public static void main(String[] args) {
        ThirdMaximumNumber_414 main = new ThirdMaximumNumber_414();
        System.out.println(main.thirdMax(new int[]{1, 3, 2}));
    }

}
